﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
using SmartPaginator.Extensions;

namespace SmartPaginator.Elements
{
    public class ListElement: BlockContainerElement
    {
        #region Constructor

        protected ListElement(List source):base(source)
        { 
        }

        public ListElement(List source, IElementFactory factory)
            : base(source, source.ListItems, factory)
        {
        }

        #endregion

        #region Properties

        private List List { get { return Source as List; } } 

        #endregion

        #region GetEmptyCopy Method

        public override IBlockElement GetEmptyCopy()
        {
            var result = new ListElement(this.List);
            return result;
        }

        #endregion

        #region Margin Calculation

        public override double CalculateBottomMargin()
        {
            if (double.IsNaN(List.Margin.Bottom))
                return Source.GetLineHeight();

            return this.Margin.Bottom;
        }

        public override double CalculateTopMargin()
        {
            if (double.IsNaN(List.Margin.Top))
                return Source.GetLineHeight();

            return this.Margin.Top;
        }

        #endregion
    }
}
